package leecode

import "math"

func nthUglyNumber(n int) int {
	dp := make([]int, n) //第i个位置的丑数
	//初始化dp数组
	dp[0] = 1
	for i := 1; i < n; i++ {
		temp := math.MaxInt
		for j := 0; j < i; j++ {
			if dp[j]*2 > dp[i-1] {
				temp = min(temp, dp[j]*2)
			} else if dp[j]*3 > dp[i-1] {
				temp = min(temp, dp[j]*3)
			} else if dp[j]*5 > dp[i-1] {
				temp = min(temp, dp[j]*5)
			}
		}
		dp[i] = temp
	}
	return dp[len(dp)-1]
}
